package com.myframe.www.main.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;

import com.myframe.www.model.remote.bean.HomeHotBean;
import com.myframe.www.model.remote.bean.HotListBean;
import com.myframe.www.view.recyclerview.DefaultRecyclerViewAdapter;

/**
 * Created by Administrator on 2017/12/22.
 */

public class MeAdapter extends DefaultRecyclerViewAdapter {

    private BannerCell bannerCell;
    private ListCell listCell;
    private HomeHotBean source;

    public MeAdapter(Context context) {
        super(context);
        openLoadMore();
        setLayoutManager(new LinearLayoutManager(context));
        bannerCell = new BannerCell();
        listCell = new ListCell();
        addCell(bannerCell);
        addCell(listCell);
        setOnBannerClickListener();
    }

    public void setOnBannerClickListener() {
        bannerCell.setBannerItemClickListener(new BannerCell.BannerItemClickListener() {
            @Override
            public void bannerItemClick(int position) {
                if(mOnMeItemClickListener!=null){
                mOnMeItemClickListener.bannerClick(position);
                }
            }
        });
        listCell.setOnItemClickListener(new ListCell.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                if(mOnMeItemClickListener!=null){
                    mOnMeItemClickListener.itemClick(position);
                }
            }
        });
    }


    public void updateSource(HomeHotBean source) {
        this.source = source;
        bannerCell.updateSource(null);
        listCell.updateSource(null);
        initPage();
        prepare();
        bannerCell.updateSource(source.bannerListBean == null ? null : source.bannerListBean.getList());
        listCell.updateSource(source.list == null ? null : source.list.getList());
        notifySuccess();
    }

    public void updateMore(HotListBean moreSource) {
        prepare();
        listCell.updateMore(moreSource == null ? null : moreSource.getList());
        notifySuccess();
    }

    @Override
    public void notifyFailure() {
        super.notifyFailure();
        bannerCell.updateSource(null);
        listCell.updateSource(null);
        super.notifyFailure();
    }


    public interface OnMeItemClickListener{

        void bannerClick(int position);

        void itemClick(int position);

    }
    public OnMeItemClickListener mOnMeItemClickListener;

    public void setOnMeItemClickListener(OnMeItemClickListener onMeItemClickListener){
        mOnMeItemClickListener = onMeItemClickListener;
    }
}
